package com.online.shopping.service.impl;

import com.online.shopping.mapper.TbSpecificationMapper;
import com.online.shopping.pojo.TbSpecification;
import com.online.shopping.service.SpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Rui
 * @version 1.0
 * @date 2020/11/12 15:34
 */
@Service
public class SpecificationServiceImpl implements SpecificationService {

    @Autowired
    private TbSpecificationMapper tbSpecificationMapper;

    @Override
    public int addSpecification( TbSpecification Specification) {
        return tbSpecificationMapper.insert(Specification);
    }

    @Override
    public int deleteSpecification(Long id) {
        return tbSpecificationMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateSpecification(TbSpecification Specification) {
        return tbSpecificationMapper.updateByPrimaryKeySelective(Specification);
    }

    @Override
    public TbSpecification findSpecificationById(Long id) {
        return tbSpecificationMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<TbSpecification> findAllSpecifications() {
        return tbSpecificationMapper.selectByExample(null);
    }

    @Override
    public Long[] deleteManySpecifications(Long[] ids) {
        for (Long id : ids) {
            tbSpecificationMapper.deleteByPrimaryKey(id);
        }
        return ids;
    }

}
